/**
 * Project Name:meatball-core
 * File Name:MeatballWeixinInterceptor.java
 * Package Name:com.meatball.Interceptor
 * Date:2018年4月9日上午10:10:30
 * Copyright (c) 2018, zhang.xiangyu@foxmail.com All Rights Reserved.
*/
package com.meatball.Interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.druid.util.StringUtils;
import com.meatball.component.SpringUtil;

import java.lang.reflect.Method;

/**   
 * @Title: MeatballWeixinInterceptor.java 
 * @Package com.meatball.Interceptor 
 * @Description: TODO(微信拦截器) 
 * @author jw  
 * @date 2018年4月9日 上午10:10:30 
 * @version V1.0   
 */
public class MeatballWeixinInterceptor implements HandlerInterceptor {
	// 实例化bean
	/*private Object oLoginApiService;
	MeatballWeixinInterceptor() {
		this.oLoginApiService = SpringUtil.getBean("loginApiService");

	}*/

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		/*Method m = this.oLoginApiService.getClass().getDeclaredMethod("getWeixinUserResult",String.class);
		String requestUrl = request.getRequestURL().toString();

		// 如果为.txt文件则直接返回true
		if(requestUrl.contains(".txt")) return true;

		if (requestUrl.contains("weixin")) {

	        String code = request.getParameter("code");
//	        System.out.println("==========================code=" + code);
	        if (!StringUtils.isEmpty(code)) {
	          //return loginApiService.getWeixinUserResult(code);
				return (boolean)m.invoke(this.oLoginApiService.getClass().newInstance(), code);
	        }  
//	        SecurityUtils.getSubject().getSession().setAttribute("wxuid", "o-Svd0rQHHoHDXbisFOC0BDTLs14");
//	        return true;
	    }*/
		return false;
	}

}
